package DataStructure.peixu;

public class Insertion {
    public static void sort(Comparable[] a){
        for (int i = 0; i < a.length-1; i++) {
            for (int j = i; j>=0 ; j--) {
                if(greater(a[j],a[j+1])){
                    exch(a,j,j+1);
                }else {
                    break;
                }
            }
        }
    }

    private static boolean greater(Comparable v,Comparable w){
        return v.compareTo(w)>0;
    }

    private static void exch(Comparable[] a,int i,int j){
        Comparable temp = a[i];
        a[i]=a[j];
        a[j]=temp;
    }
}
